import request from '../../request/index'
const state = {
    user: [],
    list: [],
    data: []
}
const getters = {

}
const mutations = {
    user(state, data) {
        state.user = data
    },
    list(state, data) {
        state.list = data
    },
    jiequ(state, obj) {
        let ass = (obj.id - 1) * obj.ids
        let asd = ass + obj.ids
        let list = state.list.slice(ass, asd)
        state.data = list
    },
    chaxun(state, obj) {
        function increment(data) {
            if (obj.shou === "") {
                return data;
            } else {
                return data.filter(item => {
                    return item.user === obj.shou
                })
            }
        }
        function doubleUp(data) {
            if (obj.deng === "") {
                return data;
            } else {
                return data.filter(item => {
                    return item.dengji === obj.deng
                })
            }
        }
        function output(data) {
            if (obj.biao === "") {
                state.list = data
                jiequs()
            } else {
                state.list = data.filter(item => {
                    return item.biaoqian === obj.biao
                })
                jiequs()
            }
        }
        var p = Promise.resolve(state.user);
        p.then(increment)
            .then(doubleUp)
            .then(output)
        const jiequs = () => {
            this.commit("client/jiequ", { id: 1, ids: obj.num })
        }
    },
    chong(state){
        state.list = state.user
        this.commit("client/jiequ", { id: 1, ids: 5 })
    }
}
const actions = {
    async user(content) {
        await request({
            url: "/froms/user",
            method: "GET",
            params: {}
        }).then(res => {
            content.commit('user', res)
            content.commit('list', res)
            content.commit('jiequ', { id: 1, ids: 5 })
        });
    }
}
export default {
    namespaced: true,
    state,
    getters,
    mutations,
    actions
}